package com.scu.gkvr_system_backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scu.gkvr_system_backend.mapper.MajorsMapper;
import com.scu.gkvr_system_backend.pojo.MajorInfo;
import com.scu.gkvr_system_backend.pojo.Majors;
import com.scu.gkvr_system_backend.service.MajorsService;
import com.scu.gkvr_system_backend.vo.MajorsGetListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
* @author qinyc
* @description 针对表【majors(专业表)】的数据库操作Service实现
* @createDate 2024-05-09 00:41:37
*/
@Service
public class MajorsServiceImpl extends ServiceImpl<MajorsMapper, Majors>
    implements MajorsService{

    @Autowired
    private MajorsMapper majorsMapper;

    @Override
    public Map<String, Object> getListMajors(Integer page, String degreesName) {
        //判断学位名称是否是全部
        if("全部".equals(degreesName)){
            degreesName = null;
        }
        //创建分页对象
        Page page1 = new Page(page, 10);
        //自定义分页处理
        IPage<MajorsGetListVO> iPage = majorsMapper.getListMajors(page1,degreesName);
        //封装Map
        Map<String, Object> map = new HashMap<>();
        //存入总条数
        map.put("total", iPage.getTotal());
        //存入数据集
        map.put("data", iPage.getRecords());
        return map;
    }
    @Override
    public Map<String, Object> SearchByName(int page, String majorName) {
        Map<String, Object> result = new HashMap<>();
        Page page1 = new Page(page, 10);
        Page<MajorsGetListVO> majorInfoPage =majorsMapper.searchByName(page1,majorName);
        result.put("majors", majorInfoPage.getRecords());
        result.put("total", majorInfoPage.getTotal());
        return result;
    }
}




